<?php
/**
 * Created by PhpStorm.
 * User: Mak
 * Date: 2016/1/6
 * Time: 17:03
 */

namespace Home\Controller;
use Think\Controller;

class SxController extends Controller{

    public function _initialize(){
        header("content-type:text/html; charset=utf-8");
        $flag = session('?dataInfo');
        if(!$flag){
            $this->error("非法登录",U('Home/Index/index'));
        }

    }

    public function sx(){
        $ret=D("Sx");
        $sxinfo = $ret->getList();
        $this->assign("sxinfo",$sxinfo)->assign("title","实训信息登记");
        $this->display();
    }

    public function addsx(){
        $sx=M('sx');
        $dataList=array(
            "name"=>session("dataInfo.name"),
            "worktile"=>I("post.worktile"),
            "git"=>I("post.git"),
            "tel"=>I("post.tel")
        );

        if($ret=$sx->add($dataList)){
//            $this->success('提交成功！');
//            $this->redirect('Sx/sx');
            echo "<script type='text/javascript'>
                    alert('提交成功！');
                    location.href='sx';
                   </script>";
        }else{
            $this->error("提交失败");
        }
    }

    public function delsx(){

        $id=I("get.id");
        $sx=D("sx");
        if($sx->del($id)){
//            $this->success('删除成功！');
            echo "<script type='text/javascript'>
                    alert('删除成功！');
                    location.href='sx';
                   </script>";
        }else{
            $this->error("删除失败");
        }
    }

    public  function updatesx(){
        $id=I("get.id");
        $sx=D("sx");
        $ret=$sx->getItem($id);
        $this->assign("upret",$ret);
        $this->display();

        if(I('post.')){
            $data=I('post.');
            $ret=M('sx')->where("id={$id}")->save($data);
            if(false !== $ret || 0 !== $ret){
                echo "<script type='text/javascript'>
                    alert('修改成功！');
                    location.href='sx';
                   </script>";
            }else {
                $this->error('修改失败');
            }
        }

    }

//    public function upsx(){
//        $data=I('post.');
//        $ret=M('sx')->where("id={$id}")->save($data);
//        if(false !== $ret || 0 !== $ret){
//            S('id',null);
//            echo "<script type='text/javascript'>
//                    alert('修改成功！');
//                    location.href='sx';
//                   </script>";
//        }else {
//            $this->error('修改失败');
//        }
//    }
}